package com.gexiaobao.pigeon.ui.fragment.mine.pigeon

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.BaseFragment
import com.gexiaobao.pigeon.app.ext.initClose
import com.gexiaobao.pigeon.app.rxui.tablayout.listener.OnTabSelectListener
import com.gexiaobao.pigeon.databinding.FragmentMyPigeonBinding
import com.gexiaobao.pigeon.ui.adapter.MyPagerAdapter
import com.gexiaobao.pigeon.viewmodel.MyPigeonViewModel
import me.hgj.jetpackmvvm.ext.nav
import me.hgj.jetpackmvvm.ext.navigateAction
import me.hgj.jetpackmvvm.ext.util.setOnclickNoRepeat

/**
 * @Author      : hxw
 * @Date        : 2023/5/31 15:11
 * @Describe    : 我的赛鸽
 */
class FragmentMyPigeon : BaseFragment<MyPigeonViewModel, FragmentMyPigeonBinding>() {
    override fun initView(savedInstanceState: Bundle?) {
        setStatusBarTranslucent()
        mDatabind.tabLayoutPigeonMine.setTabData(arrayOf(getString(R.string.autotrophy), getString(R.string.shanty)))
        mDatabind.toolbar.initClose("") {
            nav().navigateUp()
        }

        mDatabind.tabLayoutPigeonMine.textsize = 16f
        val tabTitles = arrayListOf(getString(R.string.autotrophy), getString(R.string.shanty))
        val fragments = arrayListOf<Fragment>(FragmentAutotrophic(), FragmentFoster())
        mDatabind.viewpage.adapter = context?.let { MyPagerAdapter(childFragmentManager, it, fragments, tabTitles) }

        mDatabind.tabLayoutPigeonMine.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                mDatabind.viewpage.currentItem = position
            }

            override fun onTabReselect(position: Int) {}
        })
        mDatabind.viewpage.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
            }

            override fun onPageSelected(position: Int) {
                mDatabind.tabLayoutPigeonMine.currentTab = position
            }

            override fun onPageScrollStateChanged(state: Int) {}
        })
        mDatabind.viewpage.currentItem = 0
    }


    override fun onBindViewClick() {
        super.onBindViewClick()
        setOnclickNoRepeat(mDatabind.tvAddPigeon) {
            when (it) {
                mDatabind.tvAddPigeon -> {
                    nav().navigateAction(R.id.action_mien_pigeon_to_add_pigeon, Bundle().apply {
                        putString("title", getString(R.string.add_pigeon))
                        putInt("type", 1)
                    })
                }
            }
        }
    }
}